#include "stdio.h"
#define MaxSize 10 

typedef int ElemType;
typedef struct{
   ElemType data[MaxSize];
   int listLength;
} orderList;

// �������� 
void InitList(orderList *p);
void ListPush(orderList *p,ElemType elem);
void ListInsert(orderList *p,int position,ElemType elem);
void ListDelete(orderList *p,int position);
void printfElem(orderList *p);
ElemType ListPop(orderList *p);




ElemType ListGetElemnt(orderList *p,int position);






// ��������� 
void main(){
  orderList list;
  InitList(&list);
  ListPush(&list,1);
  ListPush(&list,2);
  ListPush(&list,3);
  ListPush(&list,4);
  ListPush(&list,5);
  ListInsert(&list,6,100);
  printfElem(&list); 
} 

// ��ʼ������ 
void InitList(orderList *p){
	(*p).listLength = 0;
}

// β������Ԫ�� 
void ListPush(orderList *p,ElemType elem){
	 int length = (*p).listLength;
	 if(length>=MaxSize){
	    printf("�����Ѿ�����,�޷�����������\n");
	    return; 
	 }	
	 (*p).data[length] = elem;
	 (*p).listLength++;
} 

// β��ɾ��Ԫ��
ElemType ListPop(orderList *p){
  int length = (*p).listLength;
  if(length<=0){
    printf("�������鳤��Ϊ0,�޷�ɾ��β��Ԫ��"); 
    return;
  }
  int needElem = (*p).data[length-1];
  (*p).listLength--;
  return needElem;
}
 
// ��ӡһ������ 
void printfElem(orderList *p){
	int i;
	int length = (*p).listLength;
	for(i=0;i<length;i++){
	   printf("��%dԪ�ص�ֵΪ%d\n",i+1,(*p).data[i]);
	}
	printf("�������ܳ���Ϊ:%d",(*p).listLength);
}

// ��������ĳ��λ�ò���һ��Ԫ��
void ListInsert(orderList *p,int position,ElemType elem){
	 int length = (*p).listLength;
	 if(position >= length || position<=0 || position > MaxSize){
	 	printf("���������������Ԫ�ز���λ������\n"); 
	 	return;
	 }
     int i;
     for(i=length ;i>=position-1; i--){
	    (*p).data[i] = (*p).data[i-1];
	 }
	 (*p).data[position-1] = elem;
	 (*p).listLength+=1;
}

// ɾ��������ĳ��λ�õ�Ԫ�� 
void ListDelete(orderList *p,int position){
	int length = (*p).listLength;
	if(position > length || position<=0){
	 	printf("���������������Ԫ��ɾ��λ������\n"); 
	 	return;
	}
	int i;
	for(i=position;i<length ;i++){
	   (*p).data[i-1] = (*p).data[i];
	}
	(*p).data[length-1] = 0;
	(*p).listLength-=1;
}

// ��ȡĳ��λ�õ�Ԫ��
ElemType ListGetElemnt(orderList *p,int position){
    int length = (*p).listLength;
    if(position > length || position<=0){
	   printf("�������λ��Ԫ������,�޷���ȡ����Ԫ��\n");
	   return;
	}  
	return (*p).data[position-1];
}
 




 




